package com.ruoyi.storage.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.storage.mapper.WarehouseInfoMapper;
import com.ruoyi.storage.domain.WarehouseInfo;
import com.ruoyi.storage.service.IWarehouseInfoService;


/**
 * 仓库管理Service业务层处理
 * 
 * @author 庞一恺
 * @date 2025-01-08
 */
@Service
public class WarehouseInfoServiceImpl implements IWarehouseInfoService 
{
    @Autowired
    private WarehouseInfoMapper warehouseInfoMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询仓库管理
     * 
     * @param warehouseId 仓库管理主键
     * @return 仓库管理
     */
    @Override
    public WarehouseInfo selectWarehouseInfoByWarehouseId(Integer warehouseId)
    {
        return warehouseInfoMapper.selectWarehouseInfoByWarehouseId(warehouseId);
    }

    /**
     * 查询仓库管理列表
     * 
     * @param warehouseInfo 仓库管理
     * @return 仓库管理
     */
    @Override
    public List<WarehouseInfo> selectWarehouseInfoList(WarehouseInfo warehouseInfo)
    {
        return warehouseInfoMapper.selectWarehouseInfoList(warehouseInfo);
    }

    /**
     * 新增仓库管理
     * 
     * @param warehouseInfo 仓库管理
     * @return 结果
     */
    @Override
    public int insertWarehouseInfo(WarehouseInfo warehouseInfo)
    {
        SysUser user= sysUserMapper.selectUserById(warehouseInfo.getPrincipal()) ;

        //如果用户不存在，返回0
        if (user==null){
            return 0;

            //如果用户部门非仓储部门，返回0
        }else if(user.getDeptId()!=200){
            return 0;
        }

        return warehouseInfoMapper.insertWarehouseInfo(warehouseInfo);
    }

    /**
     * 修改仓库管理
     * 
     * @param warehouseInfo 仓库管理
     * @return 结果
     */
    @Override
    public int updateWarehouseInfo(WarehouseInfo warehouseInfo)
    {
        return warehouseInfoMapper.updateWarehouseInfo(warehouseInfo);
    }

    /**
     * 批量删除仓库管理
     * 
     * @param warehouseIds 需要删除的仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteWarehouseInfoByWarehouseIds(Integer[] warehouseIds)
    {
        return warehouseInfoMapper.deleteWarehouseInfoByWarehouseIds(warehouseIds);
    }

    /**
     * 删除仓库管理信息
     * 
     * @param warehouseId 仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteWarehouseInfoByWarehouseId(Integer warehouseId)
    {
        return warehouseInfoMapper.deleteWarehouseInfoByWarehouseId(warehouseId);
    }
}
